package com.chinadci.smartcommunitysystembackstage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinadci.smartcommunitysystembackstage.entity.ScsComplaint;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsAdmintypeMapper;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsComplaintMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author Code Duck
 * @since 2021-04-13
 */
@Service
public class ScsComplaintService{
    @Autowired
    private ScsComplaintMapper mapper;

    private Logger log= LoggerFactory.getLogger(this.getClass());

    //实现全部投诉列表
    public List<ScsComplaint> Find(String time){
        log.info("=====显示全部投诉");
        List<ScsComplaint> list=null;
        if (time!=null && time!="" && !time.equals("null")){
            list= mapper.Finds(time);
        }else{
            list= mapper.Find();
        }
        for (ScsComplaint item : list) {
            item.setName(item.getUser().getUName());
        }
        return list;
    }

    //处理投诉时先查询是否已经处理过
    public ScsComplaint Cl(int id){
        log.info("=====处理投诉时先查询是否已经处理过");
        QueryWrapper<ScsComplaint> qw=new QueryWrapper<>();
        qw.eq("c_id",id);
        ScsComplaint scs=mapper.selectOne(qw);
        return scs;
    }

    //处理投诉
    public int Update(int id){
        log.info("=====处理投诉");
        QueryWrapper<ScsComplaint> qw=new QueryWrapper<>();
        qw.eq("c_id",id);
        ScsComplaint scs=new ScsComplaint();
        scs.setCState(0);
        return mapper.update(scs,qw);
    }
}
